package proxy;

import api.Girl;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @Author shenhan
 * @Date: 2020/1/16 21:13
 * @Description:
 */
public class HanMeiMeiProxy implements InvocationHandler {
    private Girl hanMeiMei;

    public HanMeiMeiProxy(Girl hanMeiMei) {
        this.hanMeiMei = hanMeiMei;
    }

    public Object getProxyInterface() {
        return Proxy.newProxyInstance(hanMeiMei.getClass().getClassLoader(), hanMeiMei.getClass().getInterfaces(), this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        doBefore();
        return method.invoke(hanMeiMei, args);
    }

    private void doBefore() {
        System.out.println("事前干点啥");
    }
}
